<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="12">

        <template v-if="toggleSearchStatus">
        <a-col :md="4" :sm="8">
            <a-form-item label="车牌号">
              <a-input placeholder="请输入车牌号" v-model="queryParam.plateNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="识别车牌号">
              <a-input placeholder="请输入识别车牌号" v-model="queryParam.identifyPlateNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <a-form-item label="车辆类型(0,无牌车，1,有牌车)">
              <a-input placeholder="请输入车辆类型(0,无牌车，1,有牌车)" v-model="queryParam.carType"></a-input>
            </a-form-item>
          </a-col>

          </template>

        </a-row>
      </a-form>
    </div>


      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
           <a @click="handleDetail(record)">详情</a>
        </span>

      </a-table>

    <!-- table区域-end -->

    <!-- 表单区域 -->
    <parkCarAbnormalRecordDetailsDetails-modal ref="modalForm" @ok="modalFormOk"></parkCarAbnormalRecordDetailsDetails-modal>
  </a-card>
</template>

<script>
   import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {deleteAction, getAction, downFile} from '@/api/manage'
  import { filterObj } from '@/utils/util';
  import ParkCarAbnormalRecordDetailsModal from "@views/abnormalRecord/modules/ParkCarAbnormalRecordDetailsModal";

  export default {
    name: "ParkCarAbnormalRecordDetailsList",
    mixins:[JeecgListMixin],
    components: {
      ParkCarAbnormalRecordDetailsModal
    },
    data () {
      return {
        description: '车场异常记录管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
          {
            title: '车牌号',
            align:"center",
            dataIndex: 'plateNo'
           },
          {
            title: '车辆性质',
            align:"center",
            dataIndex: 'carNature',
            customRender: function (t) {
              if(t===0 || t ==="0") {
                return "临时车"
              }
              if(t===1 || t ==="1") {
                return "月租车"
              }
              if(t===2 || t ==="2") {
                return "储值车"
              }
              if(t===3 || t ==="3") {
                return "军警车"
              }
              if(t===4 || t ==="4") {
                return "白名单"
              }
              if(t===5 || t ==="5") {
                return "黑名单"
              }
            }
           },

          {
            title: '出入口类型',
            align:"center",
            dataIndex: 'entOutType',
            customRender: function (armType) {
              if(armType===0 || armType ==="0") {
                return "入口"
              }
              if(armType===1 || armType ==="1") {
                return "出口"
              }
            }
           },
          {
            title: '车道名称',
            align:"center",
            dataIndex: 'armName'
           },
          {
            title: '进出时间',
            align:"center",
            dataIndex: 'entOutTime'
           },
        {
            title: '工作站名称',
            align:"center",
            dataIndex: 'workName'
           },
          {
            title: '当班操作员',
            align:"center",
            dataIndex: 'sysUserName'
          },
        {
            title: '识别照片',
            align:"center",
            dataIndex: 'imgPath',
          customRender: (record) => {
            let r = record
            return (
                <img
                    style="max-width:35px;max-height:35px;min-height:20px;min-width:20px;text-align:center;cursor:pointer;border:1px #BFBFBF solid;padding: 2px 2px 2px 2px;background-color:white;"
                    preview=''
                    src={record}
                />
            )
          }
           },
          {
              title: '创建时间',
              align:"center",
              dataIndex: 'createTime'
             }
        ],
		url: {
          list: "/parkcaroutentrancerecord/parkCarOutEntranceRecord/queryDetailsList",
       },
       queryParam: {
                "opTime_begin":"",
                "opTime_end":"",
                "type":"-1",

              },
              isorter:{
               column: 'createTime',
               order: 'desc',
             },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
   created(){

         this.keyupEnter()
   },
    methods: {


      handleExportXls(fileName){

            let startTime = this.queryParam.opTime_begin;
            let endTime = this.queryParam.opTime_end;
            let dayTime = startTime;
            if (startTime== "") {
                this.$message.error("请选择导出开始日期");
                return
            }
            if ( endTime == "") {
                this.$message.error("请选择导出结束日期");
                return
            }
             if (startTime != "" && endTime != "") {
              if (startTime != endTime) {
                this.$message.error("仅支持1天数据导出,请选择导出日期");
                return
              }
            }

            if(startTime=="" && endTime != ""){
               this.$message.error("请选择开始时间");
                return
            }

             if(startTime !="" && endTime == ""){
               this.$message.error("请选择结束时间");
                return
            }


            this.queryParam.dayTime = dayTime;
           fileName =  dayTime + fileName;
           let param = {...this.queryParam};
           if (this.queryParam.opTime_begin != "" && this.queryParam.opTime_end != "") {
                               param.opTime_begin = this.queryParam.opTime_begin + " 00:00:00";
                               param.opTime_end = this.queryParam.opTime_end + " 23:59:59";
                            }

          downFile(this.url.exportXlsUrl,param).then((data)=>{
            if (!data) {
              this.$message.warning("文件下载失败")
              return
            }
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
              window.navigator.msSaveBlob(new Blob([data]), fileName+'.xls')
            }else{
              let url = window.URL.createObjectURL(new Blob([data]))
              let link = document.createElement('a')
              link.style.display = 'none'
              link.href = url
              link.setAttribute('download', fileName+'.xls')
              document.body.appendChild(link)
              link.click()
              document.body.removeChild(link); //下载完成移除元素
              window.URL.revokeObjectURL(url); //释放掉blob对象
            }
          })
        },


           onChangeStartTime(date, dateString) {
              this.queryParam.opTime_begin = dateString;
              },

              onChangeEndTime(date, dateString) {
                this.queryParam.opTime_end = dateString;
              },





        searchQuery() {
                let startTime = this.queryParam.opTime_begin;
                let endTime = this.queryParam.opTime_end;

                if (startTime != "" && endTime != "") {
                  if (startTime > endTime) {
                    this.$message.error("开始时间不能大于结束时间");
                    return
                  }
                }

                if(startTime=="" && endTime != ""){
                   this.$message.error("请选择开始时间");
                    return
                }

                 if(startTime !="" && endTime == ""){
                   this.$message.error("请选择结束时间");
                    return
                }

                this.loadData(1);
            },

                getQueryParams(){
                  let batchNumber = this.$route.query.batchNumber
                  let carEnterId=  this.$route.query.carEnterId;

                var param = Object.assign({}, this.isorter, this.queryParam);
                param.field = this.getQueryField();
                param.batchNumber=batchNumber;
                  param.carEnterId=carEnterId;
                param.pageNo = this.ipagination.current;
                param.pageSize = this.ipagination.pageSize;
                if (this.queryParam.opTime_begin != "" && this.queryParam.opTime_end != "") {
                   param.opTime_begin = this.queryParam.opTime_begin + " 00:00:00";
                   param.opTime_end = this.queryParam.opTime_end + " 23:59:59";
                }

                // delete param.createTimeRange; // 时间参数不传递后台
                return filterObj(param);
              },

                loadData(arg) {
                debugger;
                  if(!this.url.list){
                    this.$message.error("请设置url.list属性!")
                    return
                  }
                  //加载数据 若传入参数1则加载第一页的内容
                  if (arg === 1) {
                    this.ipagination.current = 1;
                  }
                  var params = this.getQueryParams();//查询条件
                  this.loading = true;
                  getAction(this.url.list, params).then((res) => {
                    if (res.success) {
                      debugger;
                      this.dataSource = res.result.list.records;
                      this.ipagination.total = res.result.total;
                    }
                    if(res.code===510){
                      this.$message.warning(res.message)
                    }
                    this.loading = false;
                  })
                },

              batchDel: function () {

              if(!this.url.deleteBatch){
                this.$message.error("请设置url.deleteBatch属性!")
                return
              }
              if (this.selectedRowKeys.length <= 0) {
                this.$message.warning('请选择一条记录！');
                return;
              } else {
                var ids = "";
                for (var a = 0; a < this.selectionRows.length; a++) {
                  ids += this.selectionRows[a].invateuserdetailId + ",";
                }
                var that = this;
                this.$confirm({
                  title: "确认删除",
                  content: "是否删除选中数据?",
                  onOk: function () {
                    deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
                      if (res.success) {
                        that.$message.success(res.message);
                        that.loadData();
                        that.onClearSelected();
                      } else {
                        that.$message.warning(res.message);
                      }
                    });
                  }
                });
              }
            },
            handleDelete: function (invateuserdetailId) {
              if(!this.url.delete){
                this.$message.error("请设置url.delete属性!")
                return
              }
              var that = this;
              deleteAction(that.url.delete, {invateuserdetailId: invateuserdetailId}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                } else {
                  that.$message.warning(res.message);
                }
              });
            },


         keyupEnter(){
                    document.onkeydown = e =>{
                        if (e.keyCode === 13  ) {
                           this.loadData(1);
                        }
                    }
                },

        }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>